import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';

export const listFieldValue = (params) => {
  return defHttp.get({url: '/infra-service/diyFormFieldValue/listValue', params});
}

export const getField = (params) => {
  return defHttp.get({url: '/infra-service/diyFormField/getField', params});
}

export const listField = (params) => {
  return defHttp.get({url: '/infra-service/diyFormField/listField', params});
}

export const pageField = (params) => {
  return defHttp.get({url: '/infra-service/diyFormField/pageField', params});
}

export const saveOrUpdateField = (params, isUpdate) => {
  let url = '/infra-service/diyFormField/' + (isUpdate ? 'updateField' : 'saveField');
  return defHttp.post({url: url, params});
}

export const deleteField = (params, handleSuccess) => {
  return defHttp.delete({url: '/infra-service/diyFormField/deleteField', data: params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

export const batchDeleteField = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({
        url: '/infra-service/diyFormField/batchDeleteField', data: params
     }, { joinParamsToUrl: true }).then(() => {
        handleSuccess(); 
     });
    }
  });
}
